//
//  PasswordManager.m
//  CBT
//
//  Created by Mr.Zhang on 2018/11/29.
//  Copyright © 2018 Mr.Zhang. All rights reserved.
//

#import "PasswordManager.h"

@implementation PasswordManager

+(void)loginPwdChangeWithID:(NSString *)ID code:(NSString *)code pwd:(NSString *)pwd areaStr:(NSString *)areaStr block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:areaStr forKey:@"area"];
    [param setObject:ID forKey:@"phone"];
    [param setObject:code forKey:@"code"];
    [param setObject:pwd forKey:@"passWord"];
    [NetWork requestWithURL:Network_Set_Password params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

+(void)sendPhoneAndEmailCodeWithID:(NSString *)ID isPhone:(BOOL)phone type:(NSString *)type areaStr:(NSString *)areaStr block:(manager_result_block)block
{
    if (phone) {
        NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
        [param setObject:areaStr forKey:@"code"];
        [param setObject:ID forKey:@"phone"];
        [param setObject:type forKey:@"type"];
        [NetWork requestWithURL:Network_SendPhoneMsg params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
            block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
        } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
            block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
        }];
    }else{
        NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
        [param setObject:ID forKey:@"email"];
        [param setObject:type forKey:@"type"];
        [NetWork requestWithURL:Network_SendEmailMsg params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
            block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
        } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
            block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
        }];
    }
    
}

/** 支付密码设置 */
+(void)payMentPwdChangeWithPwd:(NSString *)pwd lastPwd:(NSString *)lastpwd block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:[NSString isBlankString:[CBTLocalUserManager sharedInstance].userPhone] ? [CBTLocalUserManager sharedInstance].userEmail : [CBTLocalUserManager sharedInstance].userPhone forKey:@"phone"];
    [param setObject:lastpwd forKey:@"payPassword"];
    [param setObject:@"-1" forKey:@"code"];
    [NetWork requestWithURL:Network_Set_PayPassword params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

/** 支付密码修改 */
+(void)payMentPwdChangeWithID:(NSString *)ID code:(NSString *)code pwd:(NSString *)pwd areaStr:(NSString *)areaStr block:(manager_result_block)block
{
    NSMutableDictionary * param = [[NSMutableDictionary alloc]init];
    [param setObject:areaStr forKey:@"area"];
    [param setObject:ID forKey:@"phone"];
    [param setObject:pwd forKey:@"payPassword"];
    [param setObject:code forKey:@"code"];
    [NetWork requestWithURL:Network_Set_PayPassword params:param httpMethod:@"POST" finishedBlock:^(NSURLSessionDataTask *task, id  _Nullable result) {
        block(result,[result[@"code"]intValue] == 100 ? kHttpRequestResultNormal : kHttpRequestResultError,result[@"message"]);
    } failureBlock:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil,kHttpRequestResultError,kLocalizedString(@"网络异常，请稍后重试",nil));
    }];
}

@end
